package com.wfy.common.config;

import com.qiniu.util.Auth;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

/**
 * Created with IntelliJ IDEA.
 *
 * @author: wangxindong
 * @date: 2018/5/27-22:04
 */
@Configuration
public class QiniuConfig implements EnvironmentAware {

    // ================================================================
    // Constants
    // ================================================================

    // ================================================================
    // Fields
    // ================================================================

    private String accessKey;
    private String secretKey;
    /**
     * 七牛bucket
     */
    private String bucket;
    /**
     * 七牛静态资源域名
     */
    private String domain;


    // ================================================================
    // Constructors
    // ================================================================

    // ================================================================
    // Methods from/for super Interfaces or SuperClass
    // ================================================================

    @Override
    public void setEnvironment(Environment environment) {
        accessKey = environment.getProperty("qiniu.accessKey");
        secretKey = environment.getProperty("qiniu.secretKey");
        bucket = environment.getProperty("qiniu.bucket");
        domain = environment.getProperty("qiniu.domain");
    }

    // ================================================================
    // Public or Protected Methods
    // ================================================================

    @Bean
    public Auth auth() {
        Auth auth = Auth.create(accessKey, secretKey);
        return auth;
    }


    // ================================================================
    // Getter & Setter
    // ================================================================

    public String getAccessKey() {
        return accessKey;
    }

    public void setAccessKey(String accessKey) {
        this.accessKey = accessKey;
    }

    public String getSecretKey() {
        return secretKey;
    }

    public void setSecretKey(String secretKey) {
        this.secretKey = secretKey;
    }

    public String getBucket() {
        return bucket;
    }

    public void setBucket(String bucket) {
        this.bucket = bucket;
    }

    public String getDomain() {
        return domain;
    }

    public void setDomain(String domain) {
        this.domain = domain;
    }


    // ================================================================
    // Private Methods
    // ================================================================


    // ================================================================
    // Inner or Anonymous Class
    // ================================================================

    // ================================================================
    // Test Methods
    // ================================================================

}
